<template>
  <div class="gjSummary">
    <el-table
      id="outTable"
      key="gjSummary"
      :data="sumData"
      border
      ref="table"
      height="74vh"
      show-summary
      style="width: 100%; margin-top: 20px"
      :header-cell-style="{background:'#f4f4f4',padding:0,height:'40px'}"
      :cell-style="{padding:0,height:'36px'}">
      <el-table-column
        prop="subject"
        label="科目"
        sortable
        width="180">
      </el-table-column>
      <el-table-column
        prop="yuan"
        label="金额">
      </el-table-column>
      <el-table-column
        prop="wang"
        label="金额单位（万元）">
      </el-table-column>
      <el-table-column
        prop="percent"
        label="百分比">
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
import {getCollectAccount} from '../../../../network/currentAccount'

import XLSX from "xlsx";
import FileSaver from "file-saver";

export default {
  props: {
    exportExl: {
      type: Boolean,
      default: false
    }
  },
  created(){
    this._getCollectAccount()
  },
  data(){
    return {
      sumData: [],
      totalMoney: ''
    }
  },
  watch: {
    exportExl(a,b){
      if (a) {
        this.exportExcel()
      }
    }
  },
  methods: {
    _getCollectAccount(){
      getCollectAccount().then(res => {
        console.log(res)
        this.sumData = res.data.data.list
        this.totalMoney = res.data.data.totalMoney
        this.$nextTick(() => {
          this.$refs.table.doLayout()
        })
      })
    },
    // 导出Excel
    exportExcel() {
      var xlsxParam = { raw: true };//转换成excel时，使用原始的格式
      var wb = XLSX.utils.table_to_book(document.querySelector("#outTable"),xlsxParam);
      var wbout = XLSX.write(wb, {
        bookType: "xlsx",
        bookSST: true,
        type: "array"
      });
      try {
        FileSaver.saveAs(
          new Blob([wbout], { type: "application/octet-stream;charset=utf-8" }),
          "现金流水汇总.xlsx"
        );
        this.$emit("exportFinish")
      } catch (e) {
        if (typeof console !== "undefined") console.log(e, wbout);
      }
      return wbout;
    }
  }
}
</script>